package idiet.wizards.page;

import org.apache.commons.lang.StringUtils;
import org.eclipse.jface.dialogs.DialogSettings;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wb.swt.SWTResourceManager;

public class WizardPageCustomerPhysiologicInfo extends WizardPage {
	private Text textName;
	private Text textHeight;
	private Text textWeight;
	private Text textComment;
	private Text textAge;
	private Text textBust;
	private Text textWaist;
	private Text textHip;
	private String name;
	//private DialogSettings settings=new DialogSettings("settings");
	/**
	 * Create the wizard.
	 */
	public WizardPageCustomerPhysiologicInfo() {
		super("wizardPage2");
		setTitle("\u7B2C\u4E8C\u6B65\uFF1A\u6DFB\u52A0\u5BA2\u6237\u57FA\u672C\u4FE1\u606F2");
		setDescription("\u6DFB\u52A0\u5BA2\u6237\u7684\u5E74\u9F84\u3001\u8EAB\u9AD8\u3001\u4F53\u91CD\u7B49\u4FE1\u606F");
		//this.intialErrors();
		this.setPageComplete(false);
		//name=this.settings.get("name");
	}

	@Override
	public IWizardPage getNextPage() {
		// TODO Auto-generated method stub
		
		if (this.textAge.getText().trim().equals("")) {
			this.setErrorMessage("customer's age must not be empty ! ");
			return this;
		}
		if (this.textHeight.getText().trim().equals("")) {
			this.setErrorMessage("customer's height must not be empty ! ");
			return this;
		}
		if (this.textWeight.getText().trim().equals("")) {
			this.setErrorMessage("customer's weight must not be epmty ! ");
			return this;
		}
		
		this.setErrorMessage(null);
		WizardPageCustomerNurseInfo next=(WizardPageCustomerNurseInfo)super.getNextPage();
		next.setName(this.textName.getText());
		return super.getNextPage();
	}
	/**
	 * Create contents of the wizard.
	 * @param parent
	 */
	@Override
	public void createControl(Composite parent) {
		Composite container = new Composite(parent, SWT.NULL);

		setControl(container);
		GridLayout gl_container = new GridLayout(3, false);
		gl_container.marginRight = 100;
		gl_container.marginLeft = 100;
		container.setLayout(gl_container);
		
		Label lblNewLabel = new Label(container, SWT.NONE);
		lblNewLabel.setText("\u59D3\u540D\uFF1A");
		lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		
		textName = new Text(container, SWT.BORDER | SWT.READ_ONLY);
		GridData gd_textName = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
		gd_textName.widthHint = 251;
		textName.setLayoutData(gd_textName);
		//textName.setText(name);
		//CustomerWizardBasicInfo basicPage=(CustomerWizardBasicInfo)this.getPreviousPage();
		//CustomerBasicInfo basic=basicPage.getCustomerBasicInfo();
		Label label_2 = new Label(container, SWT.NONE);
		label_2.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
		label_2.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_2.setText("\u5E74\u9F84\uFF1A");
		
		textAge = new Text(container, SWT.BORDER);
		textAge.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				if(textAge.getText().trim().equals("")){
					setErrorMessage("age must not be empty ! ");
					setPageComplete(false);
				}else{
					if(!StringUtils.isNumeric(textAge.getText())){
						textAge.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
						setErrorMessage("age must be numeric ! ");
						setPageComplete(false);
					}else{
						textAge.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
						setErrorMessage(null);
						setPageComplete(true);
					}
				}
			}
		});
		GridData gd_textAge = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
		gd_textAge.widthHint = 108;
		textAge.setLayoutData(gd_textAge);
		new Label(container, SWT.NONE);
		
		Label lblNewLabel_3 = new Label(container, SWT.NONE);
		lblNewLabel_3.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
		lblNewLabel_3.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblNewLabel_3.setText("\u8EAB\u9AD8\uFF1A");
		
		textHeight = new Text(container, SWT.BORDER);
		textHeight.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				if(textHeight.getText().trim().equals("")){
					setErrorMessage("age must not be empty ! ");
					setPageComplete(false);
				}else{
					if(!StringUtils.isNumeric(textHeight.getText())){
						textHeight.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
						setErrorMessage("age must be numeric ! ");
						setPageComplete(false);
					}else{
						textHeight.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
						setErrorMessage(null);
						setPageComplete(true);
					}
				}
			}
		});
		GridData gd_textHeight = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
		gd_textHeight.widthHint = 108;
		textHeight.setLayoutData(gd_textHeight);
		
		Label lblcm = new Label(container, SWT.NONE);
		lblcm.setText("厘米（CM）");
		
		Label label = new Label(container, SWT.NONE);
		label.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
		label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label.setText("\u4F53\u91CD\uFF1A");
		
		textWeight = new Text(container, SWT.BORDER);
		textWeight.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				if(textWeight.getText().trim().equals("")){
					setErrorMessage("age must not be empty ! ");
					setPageComplete(false);
				}else{
					if(!StringUtils.isNumeric(textWeight.getText())){
						textWeight.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
						setErrorMessage("age must be numeric ! ");
						setPageComplete(false);
					}else{
						textWeight.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
						setErrorMessage(null);
						setPageComplete(true);
					}
				}
			}
		});
		GridData gd_textWeight = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
		gd_textWeight.widthHint = 108;
		textWeight.setLayoutData(gd_textWeight);
		
		Label lblkg = new Label(container, SWT.NONE);
		lblkg.setText("公斤（Kg）");
		
		Label lblNewLabel_1 = new Label(container, SWT.NONE);
		lblNewLabel_1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblNewLabel_1.setText("Bust");
		
		textBust = new Text(container, SWT.BORDER);
		textBust.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		textBust.addModifyListener(new ModifyListener(){

			@Override
			public void modifyText(ModifyEvent e) {
				// TODO Auto-generated method stub
				if(!StringUtils.isNumeric(textBust.getText())){
					textBust.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
					setErrorMessage("age must be numeric ! ");
					setPageComplete(false);
				}else{
					textBust.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
					setErrorMessage(null);
					setPageComplete(true);
				}
			}
			
		});
		new Label(container, SWT.NONE);
		
		Label lblNewLabel_2 = new Label(container, SWT.NONE);
		lblNewLabel_2.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblNewLabel_2.setText("Waist");
		
		textWaist = new Text(container, SWT.BORDER);
		textWaist.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		textWaist.addModifyListener(new ModifyListener(){

			@Override
			public void modifyText(ModifyEvent e) {
				// TODO Auto-generated method stub
				if(!StringUtils.isNumeric(textWaist.getText())){
					textWaist.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
					setErrorMessage("age must be numeric ! ");
					setPageComplete(false);
				}else{
					textWaist.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
					setErrorMessage(null);
					setPageComplete(true);
				}
			}
			
		});
		new Label(container, SWT.NONE);
		
		Label lblNewLabel_4 = new Label(container, SWT.NONE);
		lblNewLabel_4.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		lblNewLabel_4.setText("Hip");
		
		textHip = new Text(container, SWT.BORDER);
		textHip.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		textHip.addModifyListener(new ModifyListener(){

			@Override
			public void modifyText(ModifyEvent e) {
				// TODO Auto-generated method stub
				if(!StringUtils.isNumeric(textHip.getText())){
					textHip.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
					setErrorMessage("age must be numeric ! ");
					setPageComplete(false);
				}else{
					textHip.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
					setErrorMessage(null);
					setPageComplete(true);
				}
			}
			
		});
		new Label(container, SWT.NONE);
		
		Label label_1 = new Label(container, SWT.NONE);
		label_1.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
		label_1.setText("\u5907\u6CE8\uFF1A");
		
		textComment = new Text(container, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI);
		GridData gd_textComment = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
		gd_textComment.heightHint = 61;
		textComment.setLayoutData(gd_textComment);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
		textName.setText(name);
	}

	@Override
	public IDialogSettings getDialogSettings() {
		// TODO Auto-generated method stub
		DialogSettings settings=new DialogSettings("settings");
		settings.put("age", textAge.getText());
		settings.put("height", textHeight.getText());
		settings.put("weight", textWeight.getText());
		settings.put("comment", textComment.getText());
		settings.put("waist", textWaist.getText());
		//if(!textBust.getText().trim().equals(""))
		settings.put("bust", textBust.getText());
		settings.put("hip", textHip.getText());
		return settings;
	}
}
